package com.camp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.camp.domain.Guanggao;
import com.camp.service.IGuanggaoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广告最新Controller
 * 
 * @author ruoyi
 * @date 2024-10-22
 */
@RestController
@RequestMapping("/camp/guanggao")
public class GuanggaoController extends BaseController
{
    @Autowired
    private IGuanggaoService guanggaoService;

    /**
     * 查询广告最新列表
     */
    @PreAuthorize("@ss.hasPermi('camp:guanggao:list')")
    @GetMapping("/list")
    public TableDataInfo list(Guanggao guanggao)
    {
        startPage();
        List<Guanggao> list = guanggaoService.selectGuanggaoList(guanggao);
        return getDataTable(list);
    }

    /**
     * 导出广告最新列表
     */
    @PreAuthorize("@ss.hasPermi('camp:guanggao:export')")
    @Log(title = "广告最新", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Guanggao guanggao)
    {
        List<Guanggao> list = guanggaoService.selectGuanggaoList(guanggao);
        ExcelUtil<Guanggao> util = new ExcelUtil<Guanggao>(Guanggao.class);
        util.exportExcel(response, list, "广告最新数据");
    }

    /**
     * 获取广告最新详细信息
     */
    @PreAuthorize("@ss.hasPermi('camp:guanggao:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(guanggaoService.selectGuanggaoById(id));
    }

    /**
     * 新增广告最新
     */
    @PreAuthorize("@ss.hasPermi('camp:guanggao:add')")
    @Log(title = "广告最新", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Guanggao guanggao)
    {
        return toAjax(guanggaoService.insertGuanggao(guanggao));
    }

    /**
     * 修改广告最新
     */
    @PreAuthorize("@ss.hasPermi('camp:guanggao:edit')")
    @Log(title = "广告最新", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Guanggao guanggao)
    {
        return toAjax(guanggaoService.updateGuanggao(guanggao));
    }

    /**
     * 删除广告最新
     */
    @PreAuthorize("@ss.hasPermi('camp:guanggao:remove')")
    @Log(title = "广告最新", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(guanggaoService.deleteGuanggaoByIds(ids));
    }
}
